#include "log.h"
#include <string.h>

//初始化客户端日志
void init_client_log(const char *log_file) {
    FILE *fp = fopen(log_file, "a");
    if (fp == NULL) {
        perror("init_client_log: 创建日志文件失败");
        return;
    }
    time_t now = time(NULL);
    char time_str[64];
    strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", localtime(&now));
    fprintf(fp, "[%s] [INFO] 客户端日志初始化完成\n", time_str);
    fclose(fp);
}

//写入客户端日志
void client_log_write(const char *log_file, const char *level, const char *message) {
    FILE *fp = fopen(log_file, "a");
    if (fp == NULL) {
        perror("client_log_write: 打开日志文件失败");
        return;
    }
    time_t now = time(NULL);
    char time_str[64];
    strftime(time_str, sizeof(time_str), "%Y-%m-%d %H:%M:%S", localtime(&now));
    fprintf(fp, "[%s] [%s] %s\n", time_str, level, message);
    fclose(fp);
}